package com.huawei;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created by Z-hong on 2024/7/19.
 */

public class HJ50_GPT {
    static Map<Character, Character> bracketMap = new HashMap<>(); // 括号配对映射

    static {
        bracketMap.put('}', '{');
        bracketMap.put(')', '(');
        bracketMap.put(']', '[');
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.next(); // 读取输入表达式
        sc.close();

        Stack<String> numberStack = new Stack<>(); // 数字栈
        Stack<Character> operatorStack = new Stack<>(); // 操作符栈

        char[] charArray = input.toCharArray();

        // 中缀表达式转后缀表达式
        for (int i = 0; i < input.length(); i++) {
            char currentChar = charArray[i];
            if (Character.isDigit(currentChar)) { // 处理数字
                StringBuilder numberBuilder = new StringBuilder();
                numberBuilder.append(currentChar);
                while (i + 1 < input.length() && Character.isDigit(charArray[i + 1])) { // 处理多位数
                    numberBuilder.append(charArray[++i]);
                }
                numberStack.push(numberBuilder.toString());
            } else if (currentChar == '-') { // 处理减号
                boolean isNegativeNumber = (i == 0) || (i > 0 && (charArray[i - 1] == '(' || charArray[i - 1] == '{' || charArray[i - 1] == '[')); // 判断是否是负数
                if (isNegativeNumber && i + 1 < input.length() && Character.isDigit(charArray[i + 1])) { // 如果是负数
                    StringBuilder numberBuilder = new StringBuilder();
                    numberBuilder.append(currentChar);
                    while (i + 1 < input.length() && Character.isDigit(charArray[++i])) { // 处理多位负数
                        numberBuilder.append(charArray[i]);
                    }
                    handleOperator(numberStack, operatorStack, '+'); // 负数视为0减去该负数，因此在此处处理为加法
                    numberStack.push(numberBuilder.toString());
                } else { // 如果是减号操作符
                    handleOperator(numberStack, operatorStack, currentChar);
                }
            } else if (isOperator(currentChar)) { // 处理其他操作符
                handleOperator(numberStack, operatorStack, currentChar);
            } else if (isOpeningBracket(currentChar)) { // 处理左括号
                operatorStack.push(currentChar);
            } else if (isClosingBracket(currentChar)) { // 处理右括号
                while (!operatorStack.isEmpty() && operatorStack.peek() != bracketMap.get(currentChar)) { // 弹出直到找到匹配的左括号
                    performOperation(numberStack, operatorStack.pop());
                }
                if (!operatorStack.isEmpty()) {
                    operatorStack.pop(); // 弹出左括号
                }
            }
        }

        while (!operatorStack.isEmpty()) { // 处理剩余的操作符
            performOperation(numberStack, operatorStack.pop());
        }

        System.out.println(numberStack.pop()); // 输出最终结果
    }

    /**
     * 处理操作符的优先级及运算
     *
     * @param numberStack 数字栈
     * @param operatorStack 操作符栈
     * @param operator 当前操作符
     */
    private static void handleOperator(Stack<String> numberStack, Stack<Character> operatorStack, char operator) {
        while (!operatorStack.isEmpty() && precedence(operatorStack.peek()) >= precedence(operator)) {
            performOperation(numberStack, operatorStack.pop()); // 弹出栈顶操作符并计算
        }
        operatorStack.push(operator); // 当前操作符入栈
    }

    /**
     * 判断是否是操作符
     *
     * @param ch 待判断字符
     * @return 如果是操作符则返回 true，否则返回 false
     */
    private static boolean isOperator(char ch) {
        return ch == '+' || ch == '-' || ch == '*' || ch == '/';
    }

    /**
     * 判断是否是左括号
     *
     * @param ch 待判断字符
     * @return 如果是左括号则返回 true，否则返回 false
     */
    private static boolean isOpeningBracket(char ch) {
        return ch == '(' || ch == '{' || ch == '[';
    }

    /**
     * 判断是否是右括号
     *
     * @param ch 待判断字符
     * @return 如果是右括号则返回 true，否则返回 false
     */
    private static boolean isClosingBracket(char ch) {
        return ch == ')' || ch == '}' || ch == ']';
    }

    /**
     * 获取操作符的优先级
     *
     * @param operator 操作符
     * @return 操作符的优先级，越高数值越大
     */
    private static int precedence(char operator) {
        switch (operator) {
            case '*':
            case '/':
                return 2;
            case '+':
            case '-':
                return 1;
            default:
                return 0;
        }
    }

    /**
     * 执行运算
     *
     * @param numberStack 数字栈
     * @param operator 操作符
     */
    private static void performOperation(Stack<String> numberStack, char operator) {
        int num2 = Integer.parseInt(numberStack.pop()); // 弹出右操作数
        int num1 = Integer.parseInt(numberStack.pop()); // 弹出左操作数
        int result;
        switch (operator) {
            case '+':
                result = num1 + num2;
                break;
            case '-':
                result = num1 - num2;
                break;
            case '*':
                result = num1 * num2;
                break;
            case '/':
                result = num1 / num2;
                break;
            default:
                throw new IllegalArgumentException("Invalid operator: " + operator);
        }
        numberStack.push(String.valueOf(result)); // 计算结果入栈
    }
}
